home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / PREVIEW.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  229 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Definition of print preview classes
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_PREVIEW_H)
  10. #define OWL_PREVIEW_H
  11.  
  12. #if !defined(OWL_WINDOW_H)
  13. # include <owl/window.h>
  14. #endif
  15. #if !defined(OWL_DC_H)
  16. # include <owl/dc.h>
  17. #endif
  18.  
  19. #if defined(BI_NAMESPACE)
  20. namespace OWL {
  21. #endif
  22.  
  23. // Generic definitions/compiler options (eg. alignment) preceeding the 
  24. // definition of classes
  25. #include <services/preclass.h>
  26.  
  27. class _OWLCLASS TPrintout;
  28. class _OWLCLASS TPrinter;
  29.  
  30. //
  31. // class TPreviewPage
  32. // ~~~~~ ~~~~~~~~~~~~
  33. // TPreviewPage encapsulates a window which displays print-preview data.
  34. // It provides access to the basic information necessary to paint 
  35. // print-preview data: i.e. the printer's DC. 
  36. //
  37. class _OWLCLASS TPreviewPage : public TWindow {
  38.   public:
  39.     TPreviewPage(TWindow*   parent,
  40.                  TPrintout& printout,
  41.                  TPrintDC&  prndc,
  42.                  TSize&     printExtent,
  43.                  int        pagenum = 1);
  44.  
  45.     void         SetPageNumber(int newNum);
  46.     int          GetPageNumber() const;
  47.  
  48.     // Overriden TWindow virtual
  49.     //
  50.     void         Paint(TDC& dc, bool, TRect& clip);
  51.  
  52.   protected:
  53.     void         EvSize(uint sizeType, TSize& size);
  54.  
  55.   protected_data:
  56.     int          PageNum;         // Page currently being previewed
  57.     TSize        PrintExtent;     // Size of printer device (in pixels)
  58.     TPrintout&   Printout;        // Printout which sends the output
  59.     TPrintDC&    PrintDC;         // Device context of the printer
  60.  
  61.   DECLARE_RESPONSE_TABLE(TPreviewPage);
  62.   DECLARE_CASTABLE;
  63. };
  64.  
  65. //
  66. // class TPreviewDCBase
  67. // ~~~~~ ~~~~~~~~~~~~~~
  68. // TPreviewDCBase is the base class encapsulating a 'dual' device 
  69. // context - i.e. a DC which is tied to the screen but responds as if it
  70. // were tied to a printer or some other device. A dual DC is schizophrenic
  71. // and maintains two personalities: Dr. Screen and Mr. Printer.
  72. //
  73. // When querried about it's attributes, a 'dual' DC acts as a printer DC.
  74. // When requested to modify some attributes, a 'dual' DC acts as both a
  75. // printer DC and a screen DC.
  76. // When sent output, a 'dual' DC acts as a screen DC.
  77. //
  78. // NOTE: The TPreviewDCBase provides the basics of a 'dual' device context
  79. //       object. However, this base object does not attempt to map the
  80. //       screen DC to correspond to the attributes of the printer's device
  81. //       context.
  82. //
  83. class _OWLCLASS TPreviewDCBase : public TPrintDC {
  84.   public:
  85.     TPreviewDCBase(TDC&         screen,
  86.                    TPrintDC&    printdc);
  87.  
  88.     // Overriden to return printer's HDC
  89.     //
  90.     HDC           GetAttributeHDC() const;
  91.  
  92.   protected:
  93.  
  94.     // DC of 'real' device (aka TargetDevice) whose output we're previewing
  95.     //
  96.     TPrintDC&     PrnDC;                
  97. };
  98.  
  99.  
  100. //
  101. // class TPrintPreviewDC
  102. // ~~~~~ ~~~~~~~~~~~~~~~~
  103. // TPrintPreviewDC is an enhanced 'TPreviewDCBase' where the attributes
  104. // of the screen DC are modified to corresponds [fairly] to those of the
  105. // printer. 
  106. // For example, the screen DC's extent are modified to match those of the
  107. // printers. Similarly, the default font of the screen DC is computed to
  108. // correspond closely to the default font of the printer.
  109. //
  110. class _OWLCLASS TPrintPreviewDC : public TPreviewDCBase {
  111.   public:
  112.     TPrintPreviewDC(TDC&         screen,
  113.                     TPrintDC&    printdc,
  114.                     const TRect& client,
  115.                     const TRect& clip);
  116.    ~TPrintPreviewDC();
  117.  
  118.     // Override virtual TDC select & restore functions
  119.     //
  120.     void  SelectObject(const TFont& newFont);
  121.     void  SelectStockObject(int index);
  122.     void  RestoreFont();
  123.     int   GetDeviceCaps(int index) const;
  124.  
  125.     // Dual DC synchronizing functions
  126.     //
  127.     virtual void SyncFont();
  128.     virtual void ReScale();
  129.     virtual void ReOrg();
  130.  
  131.     // Override virtual TDC color matching functions
  132.     //
  133.     TColor  SetBkColor(const TColor& color);
  134.     TColor  SetTextColor(const TColor& color);
  135.  
  136.     // Override virtual TDC viewport & window mapping functions
  137.     //
  138.     int   SetMapMode(int mode);
  139.     bool  SetViewportOrg(const TPoint& origin, TPoint far* oldOrg=0);
  140.     bool  OffsetViewportOrg(const TPoint& delta, TPoint far* oldOrg=0);
  141.  
  142.     bool  SetViewportExt(const TSize& extent, TSize far* oldExtent=0);
  143.     bool  ScaleViewportExt(int xNum, int xDenom, int yNum, int yDenom,
  144.                            TSize far* oldExtent=0);
  145.  
  146.     bool  SetWindowExt(const TSize& extent, TSize far* oldExtent=0);
  147.     bool  ScaleWindowExt(int xNum, int xDenom, int yNum, int yDenom,
  148.                          TSize far* oldExtent=0);
  149.  
  150.     // Screen device point to Logical point conversions
  151.     //
  152.     bool  SDPtoLP(TPoint* points, int count = 1) const;
  153.     bool  SDPtoLP(TRect& rect) const;
  154.     bool  LPtoSDP(TPoint* points, int count = 1) const;
  155.     bool  LPtoSDP(TRect& rect) const;
  156.  
  157.   protected_data:
  158.     HFONT     PrnFont;              // Handle of current font in the printer dc
  159.     TFont*    CurrentPreviewFont;   // Font object in PrnDC used during preview
  160. };
  161.  
  162. // Generic definitions/compiler options (eg. alignment) following the 
  163. // definition of classes
  164. #include <services/posclass.h>
  165.  
  166. #if defined(BI_NAMESPACE)
  167. } // namespace OWL
  168. #endif
  169.  
  170. // --------------------------------------------------------------------------
  171. // Inline implementation
  172. //
  173.  
  174. //
  175. // Converts device coordinates (in the 'points' parameter) into logical
  176. // coordinates using the screen device context.
  177. //
  178. inline bool
  179. TPrintPreviewDC::SDPtoLP(TPoint* points, int count) const {
  180. #if   defined(BI_PLAT_WIN32)
  181.   PRECONDITION(::GetObjectType(HDC(Handle)) != 0);
  182. #elif defined(BI_PLAT_WIN16)
  183.   PRECONDITION(::IsGDIObject(HDC(Handle)) != 0);
  184. #endif
  185.   return ::DPtoLP(HDC(Handle), points, count);
  186. }
  187.  
  188. //
  189. // Converts the device coordinates of a rectangle into logical coordinates
  190. // using the screen device context.
  191. //
  192. inline bool
  193. TPrintPreviewDC::SDPtoLP(TRect& rect) const {
  194.   return SDPtoLP(rect, 2);
  195. }
  196.  
  197. //
  198. // Converts logical coordinates (in the 'points' parameter) into device
  199. // coordinates using the screen device context.
  200. //
  201. inline bool
  202. TPrintPreviewDC::LPtoSDP(TPoint* points, int count) const {
  203. #if   defined(BI_PLAT_WIN32)
  204.   PRECONDITION(::GetObjectType(HDC(Handle)) != 0);
  205. #elif defined(BI_PLAT_WIN16)
  206.   PRECONDITION(::IsGDIObject(HDC(Handle)) != 0);
  207. #endif
  208.   return ::LPtoDP(HDC(Handle), points, count);
  209. }
  210.  
  211. //
  212. // Converts the logical coordinates of a rectangle into device coordinates
  213. // using the screen device context.
  214. inline bool
  215. TPrintPreviewDC::LPtoSDP(TRect& rect) const {
  216.   return LPtoSDP(rect, 2);
  217. }
  218.  
  219. //
  220. // Retrieves the index of the page currently being previewed [painted]
  221. // on the preview page window.
  222. //
  223. inline int
  224. TPreviewPage::GetPageNumber() const {
  225.   return PageNum;
  226. }
  227.  
  228. #endif  // OWL_PREVIEW_H
  229.